nclude <QtGui>
#include <qstandarditemmodel.h>
#include "tabhead.h"





/*

testing 11.17
*/


#include <QtGui/QWidget>
#include<QStringList>
#include<QTableWidget>
#include<QHBoxLayout>
#include<QPushButton>
#include<QLabel>
#include<QTableWidget>
#include<QStringList>
#include<QPushButton>
#include <QWidget>
#include <qtextstream.h>
#include<qfile.h>








TabDialog::TabDialog(const QString &fileName, QWidget *parent)
    : QDialog(parent)

{

   //////////////////////////////////////////////////////





  ////////////////////////////////////////////////////////////

    setFixedSize(500,500);

    QFileInfo fileInfo(fileName);

    tabWidget = new QTabWidget;
     tabWidget->addTab(new processTab(fileInfo), tr("System InFo"));
     tabWidget->addTab(new performanceTab(fileInfo), tr("perfomance"));
    tabWidget->addTab(new ApplicationsTab(fileInfo), tr("Applications"));



    buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok
                                     | QDialogButtonBox::Cancel);

    connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
    connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));

    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->addWidget(tabWidget);
    mainLayout->addWidget(buttonBox);
    setLayout(mainLayout);

    setWindowTitle(tr("proccess_admin"));

}







userTab::userTab(const QFileInfo &fileInfo, QWidget *parent)
    : QWidget(parent)
{


///////////////////////////////

    QLabel *fileNameLabel = new QLabel(tr("File Name:"));
       QLineEdit *fileNameEdit = new QLineEdit(fileInfo.fileName());

       QLabel *pathLabel = new QLabel(tr("Path:"));
       QLabel *pathValueLabel = new QLabel(fileInfo.absoluteFilePath());



       pathValueLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken);

       QLabel *sizeLabel = new QLabel(tr("Size:"));
       qlonglong size = fileInfo.size()/1024;
       QLabel *sizeValueLabel = new QLabel(tr("%1 K").arg(size));
       sizeValueLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken);

       QLabel *lastReadLabel = new QLabel(tr("Last Read:"));
       QLabel *lastReadValueLabel = new QLabel(fileInfo.lastRead().toString());
       lastReadValueLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken);

       QLabel *lastModLabel = new QLabel(tr("Last Modified:"));
       QLabel *lastModValueLabel = new QLabel(fileInfo.lastModified().toString());
       lastModValueLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken);

       QVBoxLayout *mainLayout = new QVBoxLayout;
       mainLayout->addWidget(fileNameLabel);
       mainLayout->addWidget(fileNameEdit);

       mainLayout->addStretch(1);
       setLayout(mainLayout);

//////////////////////////





}

performanceTab::performanceTab(const QFileInfo &fileInfo, QWidget *parent)
    : QWidget(parent)
{


    ///////////////////////////
           char currentFilename[1024];
           char ch;
       /////////////////////

            DIR *dp;
              struct dirent *f;
              dp = opendir("/proc/");

       int i =0;
       int j=0;
       char test[1000][256];

        while (1)
       {
                  f = readdir(dp);
                  if (!f) {break;}
                          if (((f->d_name)[0]>='0')&&((f->d_name)[0]<='9')){
                          sprintf(test[i], "%s", f->d_name);
                          sprintf(currentFilename,"/proc/%s/status", f->d_name);
                       }
                          i++;
        }
       //////////////////////////////////////////////////여기서 부터 위젯
        QTableWidget *widget;
          QHBoxLayout *layout;
          QStringList list;
          QPushButton *but1;
          QLabel *lbl;
          int a;
          int b=5;

          layout=new QHBoxLayout(this);
          widget=new QTableWidget(this);

                  list<<"pid"<<"proName"<<"descibe"<<"user";
             widget->setHorizontalHeaderLabels(list);


             for(j=0;j<i;j++)
             {
                  widget->setRowCount(j);
              }  //세로 열  잡아주기

             for(a=0;a<2;a++){
                   widget->setColumnCount(a);
                  }  //가 열  잡아주기

   widget->setItem(0,0,new QTableWidgetItem());

   widget->item(0,0)->setText("");

                  layout->addWidget(widget);
                  setLayout(layout);


         }//first for();


ApplicationsTab::ApplicationsTab(const QFileInfo &fileInfo, QWidget *parent)
    : QWidget(parent)
{
setFixedSize(350,350);

lay =new QHBoxLayout;

create();
setLayout(lay);


}



void ApplicationsTab::create(){


    lb1=new QLabel("Usging_Memory:0");
    dial1=new QDial();
    dial1->setMinimum(0);
    dial1->setMaximum(100);

    lb2=new QLabel("Memory_Number:0");
    dial2=new QDial();
    dial2->setMinimum(0);
    dial2->setMaximum(100);

    lb3=new QLabel("Memory_Remain:0");
    dial3=new QDial();
    dial3->setMinimum(0);
    dial3->setMaximum(100);



    QVBoxLayout *VLayout = new QVBoxLayout();
    VLayout->addWidget(lb1);
    VLayout->addWidget(dial1);
    VLayout->addWidget(lb2);
    VLayout->addWidget(dial2);
    VLayout->addWidget(lb3);
    VLayout->addWidget(dial3);
    lay->addLayout(VLayout);

    connect(dial1,SIGNAL(valueChanged(int)),this,SLOT(changeValue1()));
}



void ApplicationsTab::changeValue1(){

    lb1->setText(QString("using_memory: %1").arg(dial1->value()));

}



processTab::processTab(const QFileInfo &fileInfo, QWidget *parent)
    : QWidget(parent)
{



    QVBoxLayout *m2 = new QVBoxLayout;


    QFile file("/proc/cpuinfo");  //proc안에 cpuinfo(cpu의 정보를 읽어오는)를 실행
    QFile file2("/proc/version"); //proc안에 version(리눅스버전을 읽어오는)을 실행
    QFile file3("/proc/meminfo"); //proc안에 meminfo(메모리의 정보를 읽어오는)을 실행
     file2.open(QFile::ReadOnly); // 파일을 오픈하여 데이터를 데이터를 읽어온다
        QTextStream stream2( &file2 );
         QString readVersion;
         readVersion = stream2.readLine(65);  //버전에대한 필요한 데이터를 readVersion에 넣어준다

         file3.open(QFile::ReadOnly); // 파일을 오픈하여 데이터를 데이터를 읽어온다
            QTextStream stream3( &file3 );
             QString readMemory;
             readMemory = stream3.read(28);   //메모리에대한 필요한 데이터를 readMemory에 넣어준다

         file.open(QFile::ReadOnly); // 파일을 오픈하여 데이터를 데이터를 읽어온다

        QTextStream stream( &file );
        QString line;
        QString information;
        QString cpuName;
        QString cpuMhz;
        QString cacheSize;

        line = stream.readLine(10);
        stream.readLine();
        stream.readLine();
        stream.readLine();
        stream.readLine();
        stream.readLine(12);
        cpuName = "CPU Name :"+stream.readLine(50);  //CPU 이름의 데이터를 cpuName변수에 String 형태로 받아오게 된다.
        stream.readLine();
        stream.readLine(10);
        cpuMhz = "CPU MHZ :"+stream.readLine(40) +"  MHZ";   //CPU MHZ의 데이터를 cpuMhz 변수에 받아오게 된다.
        stream.readLine(12);
        cacheSize="CacheSize :"+stream.readLine(10);      // CPU의 캐시 크기를 cacheSize에 받아오게 된다.

        information =cpuName +"\n" + cpuMhz +"\n" + cacheSize + "\n" + readMemory;  //받아온 정보를 information 변수에 저장

        QLabel*f6 = new QLabel(information);   //information 변수를 라벨로 생성
        QLabel*f7= new QLabel(readVersion);  //readVersion 변수를 라벨로 생성
        m2->addWidget(f6);   //생성된 라벨을 붙이기
        m2->addWidget(f7);  //생성된 라벨을 붙이기
        setLayout(m2);

}


